*** Settings ***
Library    Collections
*** Test Cases ***
Create A Simple Dictionary
    ${my_dict}=    Create Dictionary    name=John    age=30    city=New York
    Log    ${my_dict}
    Log Many  &{my_dict}
    # 访问字典的值
    Log      ${my_dict['name']}
    # 访问方法2
    ${name}=    Get From Dictionary    ${my_dict}    name
    Log     ${name}

Add Or Modify Key In Dictionary
    ${my_dict}=    Create Dictionary    name=John    age=30
    Set To Dictionary    ${my_dict}    city    New York
    # 更新
    Set To Dictionary    ${my_dict}    age    31   # 修改age的值为31
    Log    ${my_dict}    # 输出 {'name': 'John', 'age': 31, 'city': 'New York'}

Remove Key From Dictionary
    ${my_dict}=    Create Dictionary    name=John    age=30    city=New York
    Remove From Dictionary    ${my_dict}    age
    Log    ${my_dict}    # 输出 {'name': 'John', 'city': 'New York'}

# 字典迭代
Iterate Over Dictionary
    #获取所有的key
    ${my_dict}=    Create Dictionary    name=wanfeng  age=20  city=xian
    #  看作一个整体${dict}
    ${dict_keys}=    Get Dictionary Keys    ${my_dict}
    ${dict_values}=    Get Dictionary Values    ${my_dict}
    Log    ${dict_keys}
    Log    ${dict_values}

*** Test Cases ***
Iterate Over Dictionary1
    ${my_dict}=    Create Dictionary    name=John    age=30    city=New York
    ${keys}=    Get Dictionary Keys    ${my_dict}
    FOR    ${key}    IN    @{keys}
       ${value}=    Get From Dictionary    ${my_dict}    ${key}
       Log Many          Key: ${key}    Value: ${value}
    END

#